package com.example.asus_pc.myshop.bean;

import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class VegaBean {
    String vegaName;
    double totalPrice;
    double splitPrice;
    double totalNum= 0;
    double splitNum = 0;

    String vegaSpell;

    int isSelected = 0; //0未选中 1选中

    public VegaBean() {
    }

    public VegaBean(String vegaName, double totalPrice, double splitPrice) {
        this.vegaName = vegaName;
        this.totalPrice = totalPrice;
        this.splitPrice = splitPrice;
    }

    public String getVegaName() {
        return vegaName;
    }

    public void setVegaName(String vegaName) {
        this.vegaName = vegaName;
    }

    public double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public double getSplitPrice() {
        return splitPrice;
    }

    public void setSplitPrice(double splitPrice) {
        this.splitPrice = splitPrice;
    }

    public double getTotalNum() {
        return totalNum;
    }

    public void setTotalNum(double totalNum) {
        this.totalNum = totalNum;
    }

    public double getSplitNum() {
        return splitNum;
    }

    public void setSplitNum(double splitNum) {
        this.splitNum = splitNum;
    }


    public int getIsSelected() {
        return isSelected;
    }

    public void setIsSelected(int isSelected) {
        this.isSelected = isSelected;
    }

    public String getVegaSpell() {
        return vegaSpell;
    }

    public void setVegaSpell(String vegaSpell) {
        this.vegaSpell = vegaSpell;
    }

    public static class VegaBeanOrder implements Comparator<VegaBean>{

        @Override
        public int compare(VegaBean o1, VegaBean o2) {
            return o1.getVegaSpell().compareTo(o2.getVegaSpell());
        }
    }

    public static List<VegaBean> jsonToList(String json) {

        Gson gson = new Gson();
        List<VegaBean> vegaBeans = gson.fromJson(json, new TypeToken<List<VegaBean>>() {
        }.getType());//对于不是类的情况，用这个参数给出
        if(vegaBeans==null){
            return new ArrayList<VegaBean>();
        }
        for (VegaBean vegaBean : vegaBeans) {
            Log.d("vega",vegaBean.toString());
        }
        return vegaBeans;
    }

    /**
     * list to json
     *
     * @param list
     * @return
     */
    public static String listToJson(List<VegaBean> list) {

        Gson gson = new Gson();
        String json = gson.toJson(list);
        return json;
    }
}
